package com.xiaoq.thirdplatform;

import weibo4j.Oauth;
import weibo4j.http.AccessToken;

public class ThirdPlatformServiceImpl {
	
	public ThirdAccessToken getAccessTokenByCode(String thirdType, String code) {
		switch (thirdType) {
		case "Weibo":
			return getWeiboToken(code);
		case "Weixin":
			return getWeixinToken(code);
		case "QQ":
			return getQQToken(code);
		case "Toutiao":
			return getToutaiToken(code);
		default:
			break;
		}
		return null;
	}

	private ThirdAccessToken getToutaiToken(String code) {
		return null;
	}

	private ThirdAccessToken getQQToken(String code) {
		return null;
	}

	private ThirdAccessToken getWeixinToken(String code) {
		return null;
	}

	private ThirdAccessToken getWeiboToken(String code) {
		Oauth oauth = new Oauth();
		try {
			AccessToken weiboToken = oauth.getAccessTokenByCode(code);
			if (weiboToken == null) {
				throw new ThirdAccessTokenException();
			}
			return new ThirdAccessToken(weiboToken.getAccessToken(), weiboToken.getRefreshToken(), Long.parseLong(weiboToken.getExpireIn()), null);
		} catch (Exception e) {
			throw new ThirdAccessTokenException(e);
		}
	}
	
	public ThirdAccountInfo getAccountInfo(String thirdType, String accessToken) {
		switch (thirdType) {
		case "Weibo":
			return getWeiboAccountInfo(accessToken);
		case "Weixin":
			return getWeixinAccountInfo(accessToken);
		case "QQ":
			return getQQAccountInfo(accessToken);
		case "Toutiao":
			return getToutaiAccountInfo(accessToken);
		default:
			break;
		}
		return null;
	}

	private ThirdAccountInfo getToutaiAccountInfo(String accessToken) {
		return null;
	}

	private ThirdAccountInfo getQQAccountInfo(String accessToken) {
		return null;
	}

	private ThirdAccountInfo getWeixinAccountInfo(String accessToken) {
		return null;
	}

	private ThirdAccountInfo getWeiboAccountInfo(String accessToken) {
		return null;
	}
	
	
}
